package com.k136.config.filter;

import com.k136.entity.Brand;
import com.k136.service.BrandService;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * TODO Filter
 *
 * @author LiuTai
 * @version 1.00
 * @Date 2024/9/2
 */
@Component
@Order(0)
public class userFilter implements Filter {
    @Resource
    private BrandService brandService;
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException {
        System.out.println("！！！！！！！！");
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        HttpSession session=request.getSession();
        Object brand=session.getAttribute("brandList");
        if (brand==null){
            List<Brand> brandList = brandService.selBrand();
            session.setAttribute("brandList", brandList);
        }
        chain.doFilter(servletRequest, servletResponse);
    }
}
